import React from 'react'
import { createBehavior, createResource } from '@designable/core'
import { DnFC } from '@designable/react'
import { AllSchemas } from '../../schemas'
import { AllLocales } from '../../locales'
import { BraftEditor as CustomBraftEditor } from '../../customComponents/BraftEditor'
import { createFieldSchema } from '../Field'

export const BraftEditor: DnFC<React.ComponentProps<typeof CustomBraftEditor>> =
  CustomBraftEditor

BraftEditor.Behavior = createBehavior({
  name: 'BraftEditor',
  extends: ['Field'],
  selector: (node) => node.props['x-component'] === 'BraftEditor',
  designerProps: {
    propsSchema: createFieldSchema(AllSchemas.BraftEditor),
  },
  designerLocales: AllLocales.BraftEditor,
})

BraftEditor.Resource = createResource({
  icon: 'TextSource',
  elements: [
    {
      componentName: 'Field',
      props: {
        type: 'string',
        title: 'BraftEditor',
        'x-decorator': 'FormItem',
        'x-component': 'BraftEditor',
        'x-component-props': {
          disabled: false,
        },
      },
    },
  ],
})
